﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
///IPDao 的摘要说明
/// </summary>
public class IPDao
{
    DBMM dbm = new DBMM();
    DataTable dt = null;
    string sql = null;
    IPVo iv = new IPVo();

    //检查IP是否已经投票过，然后投票
    public string CheckIP(IPVo iv)
    {
        //检查IP是否已经投票过
        sql = "select * from IP where Iip=@Iip and Id=@Id and Itype=@Itype and Itime>@Itime";
        SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@Iip", iv.Iip),
                                                 new SqlParameter("@Id", iv.Id),
                                                 new SqlParameter("@Itype", iv.Itype),
                                                 new SqlParameter("@Itime", DateTime.Now.AddDays(-1))};
        dt = new DataTable();
        dt = dbm.GetTable(sql, sp);
        if (dt.Rows.Count > 0)
        {
            string str = "今天已投过票了！";
            return str;
        }
        else
        {
            //添加新IP
            sql = "insert into IP values(@Iip,@Itime,@Id,@Itype)";
            sp = new SqlParameter[] { new SqlParameter("@Iip", iv.Iip), 
                                                 new SqlParameter("@Itime", DateTime.Now.ToString()), 
                                                 new SqlParameter("@Id", iv.Id), 
                                                 new SqlParameter("@Itype", iv.Itype)};
            dbm.Execute(sql, sp);
            string str = "投票成功！";
            return str;
        }
    }
}
